#include "kuozhang.h"
#include "utils/deviceutils.h"
#include "utils/imghelper.h"
#include "QThread"
#include "utils/timemanager.h"
#include "utils/kuozhangmanager.h"
#include "bean/stringboxbean.h"

int KuoZhang::getTaskType()
{
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return KuoZhangManager::taskType::TYPE_ERROR;


    StringBoxBean stringBox;
    ImgHelper::getTextByImg(Scalar(0, 0, 255),Scalar(0, 0, 255),QRectF(0,0.1f, 0.5f, 0.9f),stringBox, RIL_BLOCK);
    QString word = stringBox.word;
    if(word.isNull() || word.isEmpty()){
        return KuoZhangManager::taskType::TYPE_ERROR;
    }
    word = word.replace("\n","");
    qDebug() << word;
    if(word.contains("结交信")){
        return KuoZhangManager::taskType::TYPE_SEND_MESSAGE;
    }else if(word.contains("援救")){
        return KuoZhangManager::taskType::TYPE_JIU_YUAN;
    }else if(word.contains("校场")){
        return KuoZhangManager::taskType::TYPE_XIAO_CHANG;
    }else if(word.contains("需要制作一些工艺品")){
        return KuoZhangManager::taskType::TYPE_ARTWARE;
    }else if(word.contains("你的任务还没有完成么")){
        return KuoZhangManager::taskType::TYPE_HAS_TASK;
    }
    return KuoZhangManager::taskType::TYPE_ERROR;
}

KuoZhang::KuoZhang(QWidget *widget):GamePersent(widget){
    setAutoDelete(false); //QRunable的方法默认run方法执行完后会自动销毁对象
}

void KuoZhang::initData(QList<RoleBean*> *roleBean)
{
    this->roleBeans = roleBean;
}

void KuoZhang::goTongFuRong()
{
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    DeviceUtils::sendLog(widget, "前往佟芙蓉");
    moveRoles(145, 95, this);

}

int KuoZhang::getTask()
{
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    QRectF rectf;
    if(!ImgHelper::getGameMatchPoint(":/kuozhang/icon/kuozhang/kuozhang.png",Scalar(23, 167, 255),Scalar(24, 171, 255),0.9f,QRectF(0, 0.2f,0.5f, 0.9f), &rectf)){
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return 0;
        DeviceUtils::sendLog(widget, "未找到 扩张任务,5分钟后点击");
        QThread::msleep(5 * 60 * 1000);
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return 0;
        return 1;
    }
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return 0;
    Win32Util::moveMouse((rectf.left() + rectf.right())/2 , (rectf.top() + rectf.bottom())/2);
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return 0;
    Win32Util::mouseLeftClick();
    return 2;
}

void KuoZhang::outGroup()
{
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    addBlood();
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    KuoZhangBean *kuozhang = currentRole->kuozhang;
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    moveRoles(99, 156, this);
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    clickSure();
    while(!getMapString().contains(kuozhang->groupCityEn)){
        QThread::msleep(100);
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    }
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->scene));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
}

void KuoZhang::clickSure()
{
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    if(ImgHelper::getGameMatchPoint(":/runshop/icon/button_sure.png",Scalar(22, 76, 90), Scalar(26, 159, 255),0.7f, QRectF(0.2f, 0.2f, 0.8f, 0.8f), &qRectF)){
        DeviceUtils::sendLog(widget, "点击确定按钮");
        Win32Util::moveMouse((qRectF.left() + qRectF.right())/2, (qRectF.top() + qRectF.bottom())/2);
        QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
        Win32Util::mouseLeftClick();
    }
}

void KuoZhang::findKuoZhang4List()
{
    do{
        QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
        if(ImgHelper::getGameMatchPoint(":/kuozhang/icon/kuozhang/task_list_tab.png",Scalar(26, 131, 247), Scalar(27, 136, 255),0.9f, QRectF(0.1f, 0.1f, 0.7f, 0.8f), &qRectF)){
            Win32Util::moveMouse((qRectF.right() + qRectF.left())/2, qRectF.bottom() + 70);
        }
        QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
        if(ImgHelper::getGameMatchPoint(":/kuozhang/icon/kuozhang/group_city.png",Scalar(13, 140, 239), Scalar(25, 206, 255),0.9f, QRectF(0.1f, 0.1f, 0.7f, 0.8f), &qRectF)){
            if(ImgHelper::getGameMatchPoint(":/kuozhang/icon/kuozhang/kuozhang_task.png",Scalar(33, 243, 239), Scalar(35, 245, 255),0.9f, QRectF(0.1f, 0.1f, 0.7f, 0.8f), &qRectF)){
                Win32Util::moveMouse((qRectF.right() + qRectF.left())/2, (qRectF.bottom() + qRectF.top())/2);
                QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
                Win32Util::mouseLeftClick();
                return;
            }else{
                Win32Util::moveMouse((qRectF.right() + qRectF.left())/2, (qRectF.bottom() + qRectF.top())/2);
                QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
                Win32Util::mouseLeftClick();
                QThread::msleep(100);
                Win32Util::mouseWheel(-40);
            }
        }else{
            Win32Util::mouseWheel(-100);
            if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG)return;
        }
    }while(true);
}


void KuoZhang::goRemote()
{
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    Win32Util::keyboardClick(VK_MENU, 'Q');
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    findKuoZhang4List();
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    QRectF rectf;
    KuoZhangManager::getInstance()->getJiuYuanTask(rectf,jiuYuanBean);
    Win32Util::moveMouse(rectf.right() - 10, rectf.bottom()- 3);
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    Win32Util::mouseLeftClick();
    DeviceUtils::sendLog(widget, "前往任务处");
    clickSure();
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    Win32Util::keyboardClick(VK_ESCAPE);
    while(!getMapString().contains(jiuYuanBean.remoteCityName)){
        QThread::msleep(100);
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    }

    QThread::msleep(TimeManager::getInstance()->waitNpc);
    while(GameManager::getInstantce()->isMove){
        QThread::msleep(100);
    }
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->scene));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
}

void KuoZhang::goFuBen()
{
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    if(!ImgHelper::getGameMatchPoint(":/kuozhang/icon/kuozhang/dajiedanan.png",Scalar(21, 169, 255), Scalar(23, 171, 255),0.9f, QRectF(0, 0.1f, 0.4f, 0.8f), &qRectF)){
        qDebug() << "未找到 大劫大难";
        return;
    }
    Win32Util::moveMouse((qRectF.left() + qRectF.right())/2, (qRectF.top() + qRectF.bottom())/2);
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    Win32Util::mouseLeftClick();
    DeviceUtils::sendLog(widget, "进入副本");
    while(!getMapString().contains(jiuYuanBean.fuBenNameEn)){
        QThread::msleep(100);
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    }
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->scene));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
}



void KuoZhang::outJiuYuanFuBen()
{
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    DeviceUtils::sendLog(widget, QString("前往救人处(%1 %2)").arg(jiuYuanBean.jiuRenLocationX).arg(jiuYuanBean.jiuRenLocationY));
    moveRoles(jiuYuanBean.jiuRenLocationX, jiuYuanBean.jiuRenLocationY,this);
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    clickNPC(jiuYuanBean.diZiImg, Scalar(0,255,146),Scalar (0,255,255));
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    if(!ImgHelper::getGameMatchPoint(":/kuozhang/icon/kuozhang/jiujiao_fubenout.png",Scalar(22,168,255), Scalar(24, 170,255),Setting::getInstance()->getImgDiscern(),QRectF(0, 0.1f, 0.5f, 0.8f), &qRectF)){
        return;
    }

    Win32Util::moveMouse((qRectF.left() + qRectF.right())/2, (qRectF.top() + qRectF.bottom())/2);
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    Win32Util::mouseLeftClick();
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    DeviceUtils::sendLog(widget, QString("前往出口(%1 %2)").arg(jiuYuanBean.outLocationX).arg(jiuYuanBean.outLocationY));
    moveRoles(jiuYuanBean.outLocationX,jiuYuanBean.outLocationY, this);
    while(getMapString().contains(jiuYuanBean.fuBenNameEn)){
        QThread::msleep(100);
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG)return;
    }
    QThread::msleep(TimeManager::getInstance()->scene);

}

void KuoZhang::goChuanSong()
{
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    DeviceUtils::sendLog(widget, QString("前往传送处%1 %2").arg(jiuYuanBean.chuanSongX).arg(jiuYuanBean.chuanSongY));
    moveRoles(jiuYuanBean.chuanSongX, jiuYuanBean.chuanSongY,this);
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    clickNPC(jiuYuanBean.yizhanImg);
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    QString shortCityName = currentRole->kuozhang->shortCityName;
    QString shortCityImg = KuoZhangManager::getInstance()->getCityImg(shortCityName);
    clickDest(shortCityImg, Scalar(21,168,255),Scalar(23, 171,255),Setting::getInstance()->getImgDiscern(), QRectF(0,0.2f, 0.5f, 0.9));
    CityNode *cityNode = CityManager::getInstance()->getCityNodeByName(shortCityName);
    while(!getMapString().contains(cityNode->enName)){
        QThread::msleep(100);
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    }
    QThread::msleep(TimeManager::getInstance()->scene);
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
}

void KuoZhang::back()
{
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    QList<CityNode *> backCityNode = currentRole->kuozhang->backLine;
    QString xiaoweiEnName = backCityNode.at(backCityNode.size() - 1)->enName; //校尉
    for(int i = 0 ; i< backCityNode.size() ; i++){
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_SHOP){
            return;
        }
        addBlood();
        CityNode *nextCity = backCityNode.at(i);

        QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_SHOP) return;
        DeviceUtils::sendLog(widget, QString("准备前往%1 %2,%3").arg(nextCity->name).arg(nextCity->x).arg(nextCity->y));
        qDebug() <<"准备前往"<< nextCity->name;
        moveRoles(nextCity->x, nextCity->y, this);
        QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_SHOP) return;
        if(ImgHelper::getGameMatchPoint(":/runshop/icon/button_sure.png", Scalar(22, 76, 90), Scalar(26, 159, 255),0.7f,QRectF(0.2f, 0.2f, 0.8f, 0.8f), &qRectF)){
            DeviceUtils::sendLog(widget, "点击确定按钮");
            Win32Util::moveMouse((qRectF.left() + qRectF.right()) / 2, (qRectF.top() + qRectF.bottom())/2);
            QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
            if(GameManager::getInstantce()->roleTask != ROLE_TASK_SHOP) return;
            Win32Util::mouseLeftClick();
        }



        if(nextCity->enName != xiaoweiEnName){

            while(!getMapString().contains(nextCity->enName) ){
                QThread::msleep(100);
                if(GameManager::getInstantce()->roleTask != ROLE_TASK_SHOP) return;
            }
            QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->scene));
            if(GameManager::getInstantce()->roleTask != ROLE_TASK_SHOP) return;
        }
    }
}

void KuoZhang::jiuyuan()
{
    outGroup();
    goRemote();
    goFuBen();

    killNPCs(this, jiuYuanBean.killNpcNode);
    outJiuYuanFuBen();
    goChuanSong();
    back();
}

void KuoZhang::xiaochang()
{
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    if(!ImgHelper::getGameMatchPoint(":/kuozhang/icon/kuozhang/xiaochang.png",Scalar(21, 169, 252), Scalar(23, 171, 255),0.9f, QRectF(0, 0.1f, 0.7f, 0.8f), &qRectF)){
        qDebug() << "未找到 进入校场";
        return;
    }
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    Win32Util::moveMouse((qRectF.left() + qRectF.right())/2 , (qRectF.top() + qRectF.bottom())/2);
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    Win32Util::mouseLeftClick();
    DeviceUtils::sendLog(widget, "进入校场中");
    while(!getMapString().contains("jiaochang")){
        QThread::msleep(100);
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    }
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->scene));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    QList<QPoint *> *list = getXiaoChangPath();
    killNPCs(this, list, 0);
    qDeleteAll(list->begin(), list->end());
    list->clear();
    delete list;
    list = nullptr;
}

void KuoZhang::abandonTask()
{
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    if(ImgHelper::getGameMatchPoint(":/kuozhang/icon/kuozhang/hand_task.png", Scalar(26, 131, 252), Scalar(27, 134, 255),Setting::getInstance()->getImgDiscern(), QRectF(0,0.1f,0.4f,0.9), &qRectF)){
        DeviceUtils::sendLog(widget,"有相应的材料，直接交接任务");
        Win32Util::moveMouse((qRectF.left() + qRectF.right())/2, (qRectF.top() + qRectF.bottom())/2 );
        QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
        Win32Util::mouseLeftClick();
        QThread::msleep(TimeManager::getInstance()->getDelay());
        Win32Util::keyboardClick(VK_ESCAPE);
    }else if(ImgHelper::getGameMatchPoint(":/kuozhang/icon/kuozhang/continus_task.png", Scalar(0,0,186), Scalar(0,0,188),Setting::getInstance()->getImgDiscern())){
        DeviceUtils::sendLog(widget,"没有相应的材料，放弃任务");
        Win32Util::keyboardClick(VK_MENU,'Q');
        QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
        findKuoZhang4List();
        clickDest(":/kuozhang/icon/kuozhang/abandon_task.png", Scalar(26, 132, 251), Scalar(28, 135, 255));
        QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
        clickSure();
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
        QThread::msleep(5 * 60 * 1000);
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    }else{
        DeviceUtils::sendLog(widget,"放弃任务");
        clickDest(":/kuozhang/icon/kuozhang/abandon_task.png", Scalar(26, 132, 251), Scalar(28, 135, 255));
        QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
        clickSure();
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
        QThread::msleep(5 * 60 * 1000);
        if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return;
    }

}

void KuoZhang::sendMessage()
{
    outGroup();
    goRemote();
    back();
}

int KuoZhang::hasTask()
{
    Win32Util::keyboardClick(VK_ESCAPE);
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return KuoZhangManager::taskType::TYPE_ERROR;
    Win32Util::keyboardClick(VK_MENU,'Q');
    QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
    if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) return KuoZhangManager::taskType::TYPE_ERROR;
    findKuoZhang4List();
    QRectF rectf;
    JiuYuanBean jiuyuanBean;
    return KuoZhangManager::getInstance()->getJiuYuanTask(rectf, jiuyuanBean);
}


QList<QPoint *> * KuoZhang::getXiaoChangPath()
{
    QList<QPoint *> *list = new QList<QPoint *>();
    list->append(new QPoint(51,23));
    list->append(new QPoint(49,48));
    list->append(new QPoint(26,47));
    list->append(new QPoint(26,36));
    list->append(new QPoint(14,42));
    return list;
}

void KuoZhang::callBack(QString str)
{
    DeviceUtils::sendLog(widget, str);
}

bool KuoZhang::isCancelTask()
{
    return GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG;
}

void KuoZhang::run()
{
    for(int i = 0; i < roleBeans->size(); i++){
        kuoZhangState = StatueGoGroup;
        RoleBean *roleBean = roleBeans->at(i);
        if(roleBean->kuozhang == nullptr) continue;
        currentRole = roleBean;
        if(i != 0){
            changeRole(roleBean->roleIndex);
        }
        int taskCount = 0;
        while(taskCount++ < roleBean->kuozhang->taskTotal){
            if(kuoZhangState <= StatueGoGroup){
                kuoZhangState = StatueGoGroup;
                if(goGroupCity(roleBean->kuozhang->groupCityEn,roleBean->kuozhang->groupXiaoWeiLocation , this)){
                    clickXiaoWei(roleBean->kuozhang->groupCityEn, currentRole->kuozhang->groupIndex);
                }
            }

            if(kuoZhangState <= StatueStart){
                kuoZhangState = StatueStart;
                goTongFuRong();
                clickNPC(":/kuozhang/icon/kuozhang/kuozhang_tongfurong.png");
                if(getTask() == 1) continue;
            }

            if(kuoZhangState <= StatueTaskType){
                kuoZhangState = StatueTaskType;

                int type = getTaskType();
                flag:
                if(type == KuoZhangManager::taskType::TYPE_ERROR){
                    break;
                }else if(type == KuoZhangManager::taskType::TYPE_JIU_YUAN){
                    DeviceUtils::sendLog(widget, "当前为救援任务");
                    jiuyuan();
                }else if(type == KuoZhangManager::taskType::TYPE_XIAO_CHANG){
                    DeviceUtils::sendLog(widget, "当前为校场任务");
                    xiaochang();
                }else if(type == KuoZhangManager::taskType::TYPE_SEND_MESSAGE){
                    DeviceUtils::sendLog(widget, "当前为结交信任务");
                    sendMessage();
                } else if(type == KuoZhangManager::taskType::TYPE_HAS_TASK){
                    DeviceUtils::sendLog(widget, "已接受任务");
                    type = hasTask();
                    goto flag;
                }else{
                    abandonTask();
                    break;
                }
            }

            if(kuoZhangState <= StatueBack){
                kuoZhangState = StatueBack;
            }

            if(kuoZhangState <= StatueFinish){
                kuoZhangState = StatueFinish;
                clickNPC(":/kuozhang/icon/kuozhang/kuozhang_tongfurong.png");
                QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
                if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) break;;
                clickDest(":/kuozhang/icon/kuozhang/kuozhang.png",Scalar(23, 167, 255),Scalar(24, 171, 255),0.9f,QRectF(0, 0.2f,0.5f, 0.9f));
                clickDest(":/kuozhang/icon/kuozhang/hand_task.png", Scalar(25, 129, 252), Scalar(28, 137, 255));
                QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
                if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) break;
                if(!ImgHelper::getGameMatchPoint(":/kuozhang/icon/kuozhang/kuozhang_finish.png",Scalar(25, 131, 250), Scalar(27, 134, 253),0.9f, QRectF(0, 0.1f, 0.6f, 0.8f), &qRectF)){
                    qDebug() << "未找到 继续按钮";
                    break;
                }
                Win32Util::moveMouse((qRectF.left() + qRectF.right())/2,(qRectF.top() + qRectF.bottom())/2);
                QThread::msleep(TimeManager::getInstance()->getDelay(TimeManager::getInstance()->timeOffset));
                if(GameManager::getInstantce()->roleTask != ROLE_TASK_KUO_ZHANG) break;
                Win32Util::mouseLeftClick();
            }
        }
    }
    emit finish();
}
